import {Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy, OnDestroy} from '@angular/core';
import {MineService} from "@mine/mine.service";
import {ActivatedRoute, Params, Router} from "@angular/router";
import {ToolsService} from "@shared/service/tools/tools.service";
import {AuthService} from "@shared/service/auth/auth.service";
import {ImageServeService} from "@shared/service/image/image-serve.service";
import {Subject} from "rxjs/Subject";

@Component({
  selector: 'grant-page',
  templateUrl: './grant.component.html',
  styleUrls: ['./grant.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class GrantComponent implements OnInit, OnDestroy {
  public orgUserId= '';
 public authRoleData;
  constructor(
    private mineService: MineService,
    private router: Router,
    private route: ActivatedRoute,
    public toolsService: ToolsService,
    public author: AuthService,
    public imgService: ImageServeService
  ) {
    // this.toolsService.showLoading();
    this.route.params.subscribe(params => {
        this.orgUserId = params['orgUserId'];
      });
    // console.log(this.orgUserId);
  }

  /**
   * @description 获取图片
   * @author baoww765
   * @date 2017-12-15
   * @param iconName 想要获取的图片完整名称
   * */
  getIcon(iconName: string) {
    return this.imgService.getIcon(iconName);
  }
  /**
   * @description 获取角色授权信息
   * @author baoww765
   * @date 2018-04-02
   * @param id 获取角色id
   * */
  getAuthRoleInfo() {
    this.mineService.getAuthRoleResp(this.orgUserId).subscribe(res => {
      // console.log(res);
      if (res.result === '0') {
        this.authRoleData = res.data[0];
      }
    });
  }
  /**
   * @description 路由至相关页面,根据后台配置接口，路由过去
   * @author chensk740
   * @data 2018-04-02
   **/
  goToRelatedPage(service) {
    // console.log(service);
    if (service) {
      this.router.navigateByUrl(service);
    } else {
      this.toolsService.presentConfirm('下载求苗APP，看更多精彩内容!');
    }
  }

  ngOnInit() {
this.getAuthRoleInfo();
  };

  ngOnDestroy() {
    this.toolsService.hideLoading();
  }

}
